class_name LoadingView
extends BaseView

#region 属性
@export var progress_bar:TextureProgressBar
@export var check_timer: Timer
@export var duration:float = 3
var pb_tween:Tween
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init_view():
	super.init_view()
	progress_bar.value = 0
	check_timer.one_shot = false
	check_timer.wait_time = 0.1
	check_timer.stop()
func on_enter(args:Dictionary = {}):
	super.on_enter()
	GameManager.set_blackboard_data("is_loading",true)
	GameManager.translate_game_state(GameEnum.GameState.Loading)
	_start_pb()
func on_pause(args:Dictionary = {}):
	super.on_pause()
func on_resume(args:Dictionary = {}):
	super.on_resume()
func on_exit(args:Dictionary = {}):
	super.on_exit()
func get_view_state() -> GameEnum.ViewState:
	return super.get_view_state()
#endregion
#region 公共方法
#endregion
#region 私有方法
func _start_pb():
	if pb_tween and pb_tween.is_valid():
		pb_tween.kill()
	progress_bar.value = 0
	pb_tween = create_tween()
	pb_tween.tween_property(progress_bar,"value",1,duration)
	pb_tween.tween_callback(func ():
		check_timer.start()
		)
func _check_loading_is_completed():
	if GameManager.get_blackboard_data("is_loading") == true:
		check_timer.stop()
		GameUISystem.view_manager.close_view(GameEnum.ViewType.LoadingView)
		# TODO 先暂时直接返回Gaming状态
		GameManager.translate_game_state(GameEnum.GameState.Gaming)
#endregion
#region 生命周期函数
#endregion
